package com.pithypan.common.exceptionHandler;


import com.pithypan.common.utils.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice      //包含了@ControllerAdvice注解和@ResponseBody注解
public class MyExceptionHandler {


    @ExceptionHandler(Exception.class)   //捕获指定类型的异常
    public R error(Exception e) {
        e.printStackTrace();
        System.out.println("---------------Exception异常处理器");
        return R.error().message("执行了全局异常...");
    }


    @ExceptionHandler(MyException.class)
    public R error(MyException e) {
        e.printStackTrace();
        System.out.println("---------------MyException异常处理器");
        return R.error().code(e.getCode()).message(e.getMsg());
    }

}
